package com.ksyun.alert.utils.AggregateOperations;

import com.ql.util.express.Operator;

import java.util.List;

/**
 * Sum聚合运算符
 * @author: hantou
 * @date: 2024-05-05
 */
public class SumOperator  extends Operator {
    @Override
    public Object executeInner(Object[] objects) throws Exception {
        double sum = 0d;
        for (Object obj : objects) {
            if (obj instanceof List) {
                List list = (List) obj;
                for (int i = 0; i < list.size(); i++) {
                    sum += (Double) list.get(i);
                }
            } else if (obj instanceof Double || obj instanceof Float) {
                sum += ((Number) obj).doubleValue();
            }
        }
        return sum;
    }
}
